package edu.pku.sei.act.taskStruct;

import org.dom4j.Element;

public class TaskMessage extends Ident{		
	private String taskName;
	private String sender;
	private String receiver;
	private String topic;
	private String content;
	
	public void addAttrisAndEles(Element element)
	{
		addAttributes(element);
		Element ele;
		ele = element.addElement(TagNames.TASK_NAME);
		ele.addText(taskName);
		ele = element.addElement(TagNames.SENDER);
		ele.addText(sender);
		ele = element.addElement(TagNames.RECEIVER);
		ele.addText(receiver);
		ele = element.addElement(TagNames.TOPIC);
		ele.addText(topic);
		ele = element.addElement(TagNames.CONTENT);
		ele.addText(content);
	}
	
	public String getTaskName()
	{
		return taskName;
	}
	
	public String getSender()
	{
		return sender;
	}
	
	public String getReceiver()
	{
		return receiver;
	}
	
	public String getTopic()
	{
		return topic;
	}
	
	public String getContent()
	{
		return content;
	}
	
	public TaskMessage() {
		super();
		setDefaultVal();
	}
	
	public TaskMessage(String id, String name)
	{
		super(id, name);
		setDefaultVal();
	}
	
	public TaskMessage(Element element)
	{
		super();
		setDefaultVal();
		setIdAndName(element);
		
		Element ele;
		
		ele = element.element(TagNames.TASK_NAME);
		if(ele != null) taskName = ele.getTextTrim();
		
		ele = element.element(TagNames.SENDER);
		if(ele != null) sender = ele.getTextTrim();
		
		ele = element.element(TagNames.RECEIVER);
		if(ele != null) receiver = ele.getTextTrim();
		
		ele = element.element(TagNames.TOPIC);
		if(ele != null) topic = ele.getTextTrim();
		
		ele = element.element(TagNames.CONTENT);
		if(ele != null) content = ele.getTextTrim();
	}
	
	private void setDefaultVal()
	{
		taskName = "";
		sender = "";
		receiver = "";
		topic = "";
		content = "";
	}
}
